<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class GoodsController extends Controller
{
    //
    public function getall()
    {
    	if($list = \App\Goods::all()){
    		foreach ($list as $key => $val) {
                // $discount_type = unserialize($val['discount_type']);
                // foreach ($discount_type as $dkey => $dval) {
                //     $list[$key]['discount']['type']
                //     $list[$key]['discount']['type'][$dval] = format_discount($dval);
                // }
    			$list[$key]['discountType'] = unserialize($val['discount_type']);
    		}
	    	return json_encode($list);
    	}
    }

    function format_discount($type)
    {
        switch ($type) {
            case 1:
                return '95折';
                break;
            case 2:
                return '买2赠1';
                break;
            
            default:
                break;
        }
    }
} 